package com.cyh.pangu.offer;

public class Offer53 {

    /**
     *  n(n-1)d/2
     * @param nums
     * @return
     */
    public int missingNumber(int[] nums) {
        int sumOr = (0 + nums.length + 1) * nums.length /2;
        int sum = 0;
        for (int num : nums) {
            sum += num;
        }
        return sumOr - sum;
    }

    public int missingNumber_2(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            if (i != nums[i]) {
                return i;
            }
        }
        return nums.length;
    }

    public static void main(String[] args) {
        int[] nums = {0, 1, 3};
        Offer53 offer53 = new Offer53();
        int cc = offer53.missingNumber(nums);
        System.out.println("cc:" + cc);
    }
}
